//
//  HS_PhotoCollectionViewCell.m
//  悦享
//
//  Created by 韩双 on 16/3/24.
//  Copyright © 2016年 张洪国. All rights reserved.
//

#import "HS_PhotoCollectionViewCell.h"

@interface HS_PhotoCollectionViewCell ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, retain) UITableView *tableView;

@property (nonatomic, retain) NSMutableArray *dataModelArr;  /**< 数据数组 */

@end

@implementation HS_PhotoCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    
    if (self) {
        
        [self createSubviews];
        
    }
    return self;
    
}

- (void)setHttp:(NSString *)http {
    
    _http = http;

    [self dataHundle];
}

- (void)createSubviews {
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height - 113) style:UITableViewStylePlain];
    
    [self.contentView addSubview:_tableView];
    
    _tableView.delegate = self;
    _tableView.dataSource = self;
    
    [_tableView registerClass:[HS_EssenceTableViewCell class] forCellReuseIdentifier:@"HS_EssenceTableViewCell"];
    [_tableView registerClass:[HS_EssenceOneTableViewCell class] forCellReuseIdentifier:@"HS_EssenceOneTableViewCell"]
    ;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return _dataModelArr.count;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    HS_EssenceModel *model = _dataModelArr[indexPath.row];
    
    if (indexPath.row == 0) {
        HS_EssenceOneTableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:@"HS_EssenceOneTableViewCell"];
        
        cell.model = model;
        
        return cell;
        
    }
    
    HS_EssenceTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HS_EssenceTableViewCell"];
    cell.model = model;
    
    return cell;
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.row == 0) {
        return SREEN_HEIGHT / 3;
    }
    return SREEN_HEIGHT / 6;
}


- (void)dataHundle {
    
    [APPTools GETWithURL:_http par:nil success:^(id responseObject) {
        
        self.dataModelArr = [NSMutableArray array];
        
        for (NSDictionary *dic in responseObject[@"data"]) {
            
            HS_EssenceModel *model = [HS_EssenceModel baseModelWithDic:dic];
            
            [_dataModelArr addObject:model];
        }

        NSLog(@"%@", _http);
        
        [_tableView reloadData];
        
    } filed:^(NSError *error) {
        
    }];
    
}
    

@end
